﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace GShare1._0.Server
{
    static class MessageSender
    {
        public static void SendText(string msg,Socket socket)
        {
            if (socket.Connected)
            {
                try
                {

                byte[] buffer = new byte[socket.ReceiveBufferSize];
                buffer = Encoding.ASCII.GetBytes(msg);
                Array.Resize(ref buffer, msg.Length);
                
                socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(EndSend), null);
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message + " MESSAGE SENDER " + ex.TargetSite);
                }
            }
            
            
        }

        private static void EndSend(IAsyncResult ar)
        {
            //Socket socket = (Socket)ar;
            //socket.EndSend(ar);
        }
    }
}
